home *** CD-ROM | disk | FTP | other *** search
/ MaxiMac 2000 December / MaxiMac 109.iso / Macworld on CD n°109 / Applications (Mac OS X PB) / MacOSX ScreenSavers / Source Code / Sproingees / buildlwo.c next >
Encoding:
C/C++ Source or Header  |  2000-08-17  |  1.8 KB  |  88 lines  |  [????/????]

  1.  
  2. #if !defined( lint ) && !defined( SABER )
  3. static const char sccsid[] = "@(#)buildlwo.c    4.02 97/04/20 xlockmore";
  4.  
  5. #endif
  6.  
  7. /*-
  8.  * buildlwo.c: Lightwave Object Display List Builder for OpenGL
  9.  *
  10.  * This module can be called by any GL mode wishing to use
  11.  * objects created in NewTek's Lightwave 3D.  The objects must
  12.  * first be converted to C source with my converter "lw2ogl".
  13.  * If other people are interested in this, I will put up a
  14.  * web page for it at http://www.netaxs.com/~emackey/lw2ogl/
  15.  *
  16.  * by Ed Mackey, 4/19/97
  17.  *
  18.  */
  19.  
  20. #include <OpenGL/gl.h>
  21. #include <OpenGL/glu.h>
  22. #include "buildlwo.h"
  23.  
  24. GLuint
  25. BuildLWO_sp(int wireframe, struct lwo *object)
  26. {
  27.     GLuint      dl_num;
  28.     GLfloat    *pnts, *normals, three[3], *grab;
  29.     unsigned short int *pols;
  30.     int         p, num_pnts = 0;
  31.  
  32.     dl_num = glGenLists(1);
  33.     if (!dl_num)
  34.         return (0);
  35.  
  36.     pnts = object->pnts;
  37.     normals = object->normals;
  38.     pols = object->pols;
  39.  
  40.     glNewList(dl_num, GL_COMPILE);
  41.  
  42.     if (!pols) {
  43.         num_pnts = object->num_pnts;
  44.         glBegin(GL_POINTS);
  45.         for (p = 0; p < num_pnts; ++p) {
  46.             three[0] = *(pnts++);
  47.             three[1] = *(pnts++);
  48.             three[2] = *(pnts++);
  49.             glVertex3fv(three);
  50.         }
  51.         glEnd();
  52.     } else
  53.         for (;;) {
  54.             if (num_pnts <= 0) {
  55.                 num_pnts = *pols + 2;
  56.                 if (num_pnts < 3)
  57.                     break;
  58.                 if (num_pnts == 3) {
  59.                     glBegin(GL_POINTS);
  60.                 } else if (num_pnts == 4) {
  61.                     glBegin(GL_LINES);
  62.                 } else {
  63.                     three[0] = *(normals++);
  64.                     three[1] = *(normals++);
  65.                     three[2] = *(normals++);
  66.                     glNormal3fv(three);
  67.                     if (wireframe)
  68.                         glBegin(GL_LINE_LOOP);
  69.                     else
  70.                         glBegin(GL_POLYGON);
  71.                 }
  72.             } else if (num_pnts == 1) {
  73.                 glEnd();
  74.             } else {
  75.                 grab = pnts + ((int) (*pols) * 3);
  76.                 three[0] = *(grab++);
  77.                 three[1] = *(grab++);
  78.                 three[2] = *(grab++);
  79.                 glVertex3fv(three);
  80.             }
  81.             --num_pnts;
  82.             ++pols;
  83.         }
  84.  
  85.     glEndList();
  86.  
  87.     return (dl_num);
  88. }